package com.ruoyi.web.controller.function;


import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.entity.NucleicAcid;
import com.ruoyi.system.entity.VitalSigns;
import com.ruoyi.system.service.NucleicAcidService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

import static com.ruoyi.common.utils.PageUtils.startPage;

@Api(tags = "核酸检测接口")
@RestController
@RequestMapping("/nucleicAcid")
public class NucleicAcidController extends BaseController {

    @Autowired
    private NucleicAcidService nucleicAcidService;


    @ApiOperation(value = "根据隔离人员id获取核酸检测信息")
    @Anonymous
    @GetMapping("/getNucleicAcidByIsolationId/{userId}")
    public AjaxResult getNucleicAcidByIsolationId(@PathVariable("userId") Long userId) {
       List<NucleicAcid> nucleicAcidList = nucleicAcidService.getNucleicAcidByIsolationId(userId);
        return AjaxResult.success(nucleicAcidList);
    }

    @ApiOperation(value = "查询核酸检测信息列表")
    @GetMapping("/getNucleicAcidList")
    @Anonymous
    public TableDataInfo getNucleicAcidList(NucleicAcid nucleicAcid) {
        startPage();
        List<NucleicAcid> nucleicAcidList = nucleicAcidService.getNucleicAcidList(nucleicAcid);

        return getDataTable(nucleicAcidList);
    }

    /**
     * 根据id获取核酸表信息
     * */
    @ApiOperation(value = "根据id获取核酸表信息")
    @Anonymous
    @GetMapping("/getNucleicAcidById/{id}")
    public AjaxResult getNucleicAcidById(@PathVariable("id") Long id) {
        NucleicAcid nucleicAcid = nucleicAcidService.getById(id);
        return AjaxResult.success(nucleicAcid);
    }

    /**
     *  新增核酸检测信息
     * */
    @ApiOperation(value = "新增核酸检测信息")
    @Anonymous
    @PostMapping("/addNucleicAcid")
    public AjaxResult addNucleicAcid(@RequestBody NucleicAcid nucleicAcid) {
        return toAjax(nucleicAcidService.save(nucleicAcid));
    }

    /**
     *  修改核酸检测信息
     * */
    @ApiOperation(value = "修改核酸检测信息")
    @Anonymous
    @PostMapping("/updateNucleicAcid")
    public AjaxResult updateNucleicAcid(@RequestBody NucleicAcid nucleicAcid) {
        return toAjax(nucleicAcidService.updateById(nucleicAcid));
    }

    /**
     *  删除核酸检测信息
     * */
    @ApiOperation(value = "删除核酸检测信息")
    @Anonymous
    @DeleteMapping("/deleteNucleicAcidById")
    public AjaxResult deleteNucleicAcidById(@RequestBody List<Long> ids) {
        return toAjax(nucleicAcidService.removeByIds(ids));
    }

    /**
     * 导出核酸检测信息
     * */
    @ApiOperation(value = "导出核酸检测信息")
    @RequestMapping("/export")
    @Anonymous
    public void export(HttpServletResponse response, NucleicAcid nucleicAcid) {
        List<NucleicAcid> nucleicAcidList = nucleicAcidService.getNucleicAcidList(nucleicAcid);
        ExcelUtil<NucleicAcid> util = new ExcelUtil<NucleicAcid>(NucleicAcid.class);
        util.exportExcel(response,nucleicAcidList, "生命体征数据");
    }


}
